import React from 'react'
import '../../assets/css/profile/site.less'
export default class SiteComponent extends React.Component {
    constructor(){
        super()
        this.state = {
            list:[]
        }
    }
    componentDidMount() {
        this.getData()
    }
    getData(){

        fetch(
            'http://vueshop.glbuys.com/api/user/address/index?uid='+localStorage['uid']+'&token=1ec949a15fb709370f'
        )
            .then((res) => res.json())
            .then((res) => {
                if (res.code === 200) {
                    console.log(res)
                    this.setState({
                        list:res.data
                    })
                }
            })
    }

    goBack() {
        this.props.history.goBack()
    }

    setSite(item){
        this.props.history.push({
            pathname:'/profile/siteAdd',
            query:item
        })
    }

    render() {
        return (
            <div id='site'>
                <div className='header'>
                    <div onClick={this.goBack.bind(this)}>
                        <img src="/images/user/my/返回.png" alt=""/>
                    </div>
                    <div>收货管理</div>
                    <div></div>
                </div>
                <div className='user-site'>
                    {this.state.list.map((item,index)=>{
                        return(
                            <div key={index} onClick={this.setSite.bind(this,item)}>
                                <div>
                                    <div>{item.name} &nbsp;&nbsp;&nbsp;{item.cellphone}</div>
                                    <div>
                                        {item.isdefault==='1'?
                                            <span>[默认]</span>:''
                                        }
                                        {item.province}{item.city}{item.area}{item.address}
                                    </div>
                                </div>
                                <div>
                                    <img src="/images/user/my/右箭头.png" alt=""/>
                                </div>
                            </div>
                        )
                    })}
                </div>
                <div className='add-site' onClick={() => {
                    this.props.history.push( '/profile/siteAdd')
                }}>
                    +添加新地址
                </div>
            </div>
        )
    }
}
